package JZOffer;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Lw中
 * @date 2020/11/5 9:57
 */
public class Jz03 {

    /**
     * 数组中的重复元素
     * @param nums
     * @return
     */
    public static int findRepeatNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        int repeat = -1;
        for (int num : nums) {
            if (!set.add(num)) {
                repeat = num;
                break;
            }
        }
        return repeat;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,3,4};
        int repeatNumber = findRepeatNumber(nums);
        System.out.println(repeatNumber);
    }

}
